package cn.jinjimi.app.entity;

import android.os.Bundle;

/**
 * Created by zhfu on 15/3/17.
 */
public class BXRMessage{
    /**
     * JSON Response keys:
     */
    public static final String FLAG_EXPIRATION_TIME = "_expiration_time"; //过期时间
    public static final String FLAG_TITLE = "title";
    public static final String FLAG_ALERT = "alert";
    public static final String FLAG_TYPE = "id";
    public static final String FLAG_URL = "url";
    public static final String FLAG_IMG = "img";
    public static final String FLAG_ARTICLE_ID = "article_id";

    public static final String FLAG_DISCOVER_NAME = "product_name";
    public static final String FLAG_DISCOVER_URL = "product_url";
    public static final String FLAG_DISCOVER_LIMIT = "product_limit";
    public static final String FLAG_DISCOVER_CODE = "product_code";

    public static final int MESSAGE_TYPE_ARTICLE = 0x1;
    public static final int MESSAGE_TYPE_PRODUCT = 0x2;
    public static final int MESSAGE_TYPE_WEB = 0x3;

    /**
     * properties
     */
    private String title;
    private int type;
    private String url;
    private String img;
    private String alert;
    private String articleId;

    public BXRMessage(){

    }

    public static BXRMessage createFromBundle(Bundle data){
        BXRMessage msg = new BXRMessage();
        msg.setArticleId(data.getString(FLAG_ARTICLE_ID))
                .setAlert(data.getString(FLAG_ALERT))
                .setImg(data.getString(FLAG_IMG))
                .setTitle(data.getString(FLAG_TITLE))
                .setType(data.getInt(FLAG_TYPE))
                .setUrl(data.getString(FLAG_URL));
        return msg;
    }

    public static Bundle compressToBundle(BXRMessage msg){
        Bundle data = new Bundle();
        data.putString(FLAG_URL, msg.getUrl());
        data.putInt(FLAG_TYPE, msg.getType());
        data.putString(FLAG_IMG, msg.getUrl());
        data.putString(FLAG_TITLE, msg.getTitle());
        data.putString(FLAG_ALERT, msg.getAlert());
        data.putString(FLAG_ARTICLE_ID, msg.getArticleId());
        return data;
    }


    /**
     * getter and setter start:
     */

    public String getUrl() {
        return url;
    }

    public BXRMessage setUrl(String url) {
        this.url = url;
        return this;
    }

    public BXRMessage setTitle(String title){
        this.title = title;
        return this;
    }

    public String getTitle(){
        return title;
    }

    public BXRMessage setAlert(String alert){
        this.alert = alert;
        return this;
    }

    public String getAlert(){
        return alert;
    }

    public String getImg() {
        return img;
    }

    public BXRMessage setImg(String img) {
        this.img = img;
        return this;
    }

    public int getType() {
        return type;
    }

    public BXRMessage setType(int type) {
        this.type = type;
        return this;
    }


    public String getArticleId() {
        return articleId;
    }

    public BXRMessage setArticleId(String articleId) {
        this.articleId = articleId;
        return this;
    }
}
